/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.giftmemo.ui.view;

import com.alee.laf.label.WebLabel;
import com.alee.laf.list.WebList;
import com.alee.laf.panel.WebPanel;
import com.giftmemo.objects.Person;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.BoxLayout;

/**
 *
 * @author user
 */
public class EventsPanel extends WebPanel{
    private WebLabel nameLabel;
    private WebList eventsList;
    private ListModel listModel;
    
    public EventsPanel(String name){
        nameLabel = new WebLabel(name);
        eventsList = new WebList();
        listModel = new ListModel();
        paintComponents();
    }
    private void paintComponents(){
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        add(nameLabel);
        add(eventsList);
    }
    public void setEventsList (List <Person> events){
        if (events != null){
            for (Person person : events){
                listModel.setPersonList(events);
            }
        }
    }
    
    private class ListModel extends AbstractListModel<Person>{
        
        private List <Person> person;
        
        public ListModel (){
            person = new ArrayList<>();
        }
        
        public void setPersonList (List <Person> person){
            this.person = person;
            fireIntervalAdded(eventsList, 0, person.size());
        }
        
        public Person getPersonByIndex(int index){
          
            return this.person.get(index);
        }

        @Override
        public int getSize()
        {
            return person == null ? 0: person.size();
        }

        @Override
        public Person getElementAt(int index)
        {
            if(index >= person.size() ) {
      
            }
            
            return person == null ? null :person.get(index);
        }
        
    }
    
}
